package com.jcl.core.security;

import com.jcl.core.security.entity.ResultEnum;
import com.jcl.core.security.utils.ResultUtil;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @ClassName AjaxAuthenticationFailureHandler
 * @Description 用户登录失败时返回给前端的数据
 * @Author yyliu
 * @Date 2018/12/18 11:23
 * @Version 1.0
 **/
public class AjaxAuthenticationFailureHandler implements AuthenticationFailureHandler {

    @Override
    public void onAuthenticationFailure(HttpServletRequest request,
                                        HttpServletResponse response,
                                        AuthenticationException e) throws IOException, ServletException {
        ResultUtil.failure(response, ResultEnum.USER_LOGIN_FAILED.getCode(),
                ResultEnum.USER_LOGIN_FAILED.getMessage());

    }
}
